package com.bestdreamer.date;

import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Date8Test1 {

    public static void main(String[] args) {
        List<Info> list = new ArrayList<>();
        list.add(new Info("1","20100122","041807"));
        list.add(new Info("2","20110122","041628"));
        list.add(new Info("3","20120122","041628"));
        list.add(new Info("4","20130122","041628"));
        list.add(new Info("","20140122","041628"));
        list.add(new Info("","20150122","041628"));
        List<Info> newList = list.stream().filter(info -> !StringUtils.isBlank(info.getId())).collect(Collectors.toList());
        System.out.println(newList.size());
        newList.forEach(info1 -> info1.setDatetime(getTime(info1.date, info1.time)));
        Info info = newList.stream().max(Comparator.comparing(Info::getDatetime)).get();
        System.out.println(info.getId());


    }

    private static LocalDateTime getTime(String date,String time){
        LocalTime localTime = LocalTime.ofSecondOfDay(Long.parseLong(time));
        LocalDate localDate = LocalDate.parse(date, DateTimeFormatter.BASIC_ISO_DATE);
        return LocalDateTime.of(localDate,localTime);
    }

    private static class Info{
        private String id;
        private String date;
        private String time;
        private LocalDateTime datetime;

        public Info(String id,String date,String time){
            this.id = id;
            this.date = date;
            this.time = time;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getDate() {
            return date;
        }

        public void setDate(String date) {
            this.date = date;
        }

        public String getTime() {
            return time;
        }

        public void setTime(String time) {
            this.time = time;
        }

        public LocalDateTime getDatetime() {
            return datetime;
        }

        public void setDatetime(LocalDateTime datetime) {
            this.datetime = datetime;
        }
    }
}
